package pri.damai.xiaowu.anydoor.business.singlechat;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import lombok.Data;
import pri.damai.xiaowu.anydoor.business.BaseModel;
import pri.damai.xiaowu.anydoor.netty.ChannelStore;

/**
 * 消息发送实体
 *
 * @description
 * @author YangXinFu
 * @date 9:22 2022/7/25
 **/
@Data
public class MsgReqModel implements BaseModel {

    private Integer formUserId;

    private Integer toUserId;

    private String msg;

    @Override
    public Byte code() {
        return 3;
    }

    @Override
    public void process(ChannelHandlerContext ctx) {
        Integer toUserid = this.getToUserId();
        Channel c = ChannelStore.getUserChannel(toUserid);

        if (c == null) {
            MsgRspModel res = new MsgRspModel();
            res.setStatus(1);
            res.setMsg(toUserid + ",不在线");

        } else {
            MsgRecModel res = new MsgRecModel();
            res.setFromUserId(this.getFormUserId());
            res.setMsg(this.getMsg());
        }
        this.writeAndFlush(ctx);
    }
}
